define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'annalscore/index',
                    table: 'c_annal_score',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                     	{field: 'roomid', title: __('房间号'), operate: false},
                     	{field: 'kinId', title: __('游戏ID'), operate: false},
                     	{field: 'uid', title: __('玩家ID')},
                     	{field: 'nickname', title: __('昵称'), operate: false},
                     	{field: 'win', title: __('局数'), operate: false},
                     	{field: 'score', title: __('大赢家贡献'), operate: '>', placeholder: '大于'},
                     	{field: 'sex', title: __('性别'), operate: false},
                     	{field: 'startime', title: __('开始时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange'},
                     	{field: 'endtime', title: __('结束时间'), operate: false, formatter: Table.api.formatter.datetime},
                        {field: 'gametime', title: __('游戏总时长'), operate: false},
                    ]
                ],
                onLoadSuccess: function (data) {
					$("#statistics").html(
							'<a class="btn btn-danger">总局数：' + data.statistics.wincount + '</a>&nbsp;'
							+ '<a class="btn btn-success">大赢家数：' + data.statistics.userwincount + '</a>&nbsp;' 
							+ '<a class="btn btn-info">总贡献：' + data.statistics.scorecount + '</a>&nbsp;' 
							);
                	$("#statistics").show();
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});